// function createArray(length: number, value: any): Array<any> {
// 	const result = [];
// 	for (let i = 0; i < length; i++) {
// 		result[i] = value;
// 	}
// 	return result;
// }

// const arr = createArray(3, true);

// <T>：定义了一个泛型参数：T
// value: T\Array<T> 使用泛型参数
// 当我们createArray指定泛型参数的类型时，value和返回值类型就是我们指定的类型
function createArray<T>(length: number, value: T): Array<T> {
	const result = [];
	for (let i = 0; i < length; i++) {
		result[i] = value;
	}
	return result;
}
// 调用函数指定泛型参数的类型
const arr1 = createArray<boolean>(3, true);
const arr2 = createArray<number>(3, 123);
const arr3 = createArray<string>(3, "123");

// 定义多个泛型参数
function fn<T, U, N>(x: T, y: U, z: N) {
	console.log(x, y, z);
}

fn<number, string, boolean>(1, "hello", true);

// 定义接口的泛型
interface Person<T> {
	name: string;
	age: number;
	info: T;
}

const p: Person<string> = {
	name: "jack",
	age: 18,
	info: "hello",
};

type Undefinable<T> = undefined | T;

const a: Undefinable<string> = "hello";
const b: Undefinable<number> = 123;

interface People {
	name: string;
	age: number;
	sex: string;
	address: string;
}
// 新类型：P
type P = Pick<People, "name" | "age">; // 包含

const p1: P = {
	name: "jack",
	age: 18,
};

type P1 = Omit<People, "address" | "sex">; // 排除

type P2 = Partial<People>; // 可选
const p2: P2 = {
	name: "bob",
};
